import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

// 引入element-plus的按需引入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({
  esbuild: {
    drop: ['console', 'debugger']
  },
  // base:'/zxwy/',
  base: process.env.NODE_ENV === "development" ? '/' : '/zxwy/',
  plugins: [
    vue(),
    vueJsx(),
    // 按需引入
    AutoImport({ //自动引入
      resolvers: [ElementPlusResolver()],
    }),
    Components({ //自动注册
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      "#": fileURLToPath(new URL("./types", import.meta.url)),
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
    },
  },
  // 代理跨域处理
  server: {
    proxy: {
      "/m.api": {
        target: "http://192.168.1.188:8080/",  //跨域地址http://www.zxwyit.cn:8080/
        // target:"http://www.zxwyit.cn:8080/",
        changeOrigin: true
      },
      "/upload/admin": { // 图片转网络图片
        target: "http://192.168.1.188:8080/",  //跨域地址http://www.zxwyit.cn:8080/
        // target:"http://www.zxwyit.cn:8080/",
        ws: true, // 如果要代理 websockets 配置这个参
        changeOrigin: true,//是否跨域
      }
    }
  }
});